1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.SpinButton; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.Adjustment; 31 private import gtk.CellEditableIF; 32 private import gtk.CellEditableT; 33 private import gtk.EditableIF; 34 private import gtk.EditableT; 35 private import gtk.OrientableIF; 36 private import gtk.OrientableT; 37 private import gtk.Widget; 38 private import gtk.c.functions; 39 public import gtk.c.types; 40 private import std.algorithm; 41 42 43 /** 44 * A `GtkSpinButton` is an ideal way to allow the user to set the 45 * value of some attribute. 46 * 47 *  48 * 49 * Rather than having to directly type a number into a `GtkEntry`, 50 * `GtkSpinButton` allows the user to click on one of two arrows 51 * to increment or decrement the displayed value. A value can still be 52 * typed in, with the bonus that it can be checked to ensure it is in a 53 * given range. 54 * 55 * The main properties of a `GtkSpinButton` are through an adjustment. 56 * See the [class@Gtk.Adjustment] documentation for more details about 57 * an adjustment's properties. 58 * 59 * Note that `GtkSpinButton` will by default make its entry large enough 60 * to accommodate the lower and upper bounds of the adjustment. If this 61 * is not desired, the automatic sizing can be turned off by explicitly 62 * setting [property@Gtk.Editable:width-chars] to a value != -1. 63 * 64 * ## Using a GtkSpinButton to get an integer 65 * 66 * ```c 67 * // Provides a function to retrieve an integer value from a GtkSpinButton 68 * // and creates a spin button to model percentage values. 69 * 70 * int 71 * grab_int_value (GtkSpinButton *button, 72 * gpointer user_data) 73 * { 74 * return gtk_spin_button_get_value_as_int (button); 75 * } 76 * 77 * void 78 * create_integer_spin_button (void) 79 * { 80 * 81 * GtkWidget *window, *button; 82 * GtkAdjustment *adjustment; 83 * 84 * adjustment = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0); 85 * 86 * window = gtk_window_new (); 87 * 88 * // creates the spinbutton, with no decimal places 89 * button = gtk_spin_button_new (adjustment, 1.0, 0); 90 * gtk_window_set_child (GTK_WINDOW (window), button); 91 * 92 * gtk_widget_show (window); 93 * } 94 * ``` 95 * 96 * ## Using a GtkSpinButton to get a floating point value 97 * 98 * ```c 99 * // Provides a function to retrieve a floating point value from a 100 * // GtkSpinButton, and creates a high precision spin button. 101 * 102 * float 103 * grab_float_value (GtkSpinButton *button, 104 * gpointer user_data) 105 * { 106 * return gtk_spin_button_get_value (button); 107 * } 108 * 109 * void 110 * create_floating_spin_button (void) 111 * { 112 * GtkWidget *window, *button; 113 * GtkAdjustment *adjustment; 114 * 115 * adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0); 116 * 117 * window = gtk_window_new (); 118 * 119 * // creates the spinbutton, with three decimal places 120 * button = gtk_spin_button_new (adjustment, 0.001, 3); 121 * gtk_window_set_child (GTK_WINDOW (window), button); 122 * 123 * gtk_widget_show (window); 124 * } 125 * ``` 126 * 127 * # CSS nodes 128 * 129 * ``` 130 * spinbutton.horizontal 131 * ├── text 132 * │ ├── undershoot.left 133 * │ ╰── undershoot.right 134 * ├── button.down 135 * ╰── button.up 136 * ``` 137 * 138 * ``` 139 * spinbutton.vertical 140 * ├── button.up 141 * ├── text 142 * │ ├── undershoot.left 143 * │ ╰── undershoot.right 144 * ╰── button.down 145 * ``` 146 * 147 * `GtkSpinButton`s main CSS node has the name spinbutton. It creates subnodes 148 * for the entry and the two buttons, with these names. The button nodes have 149 * the style classes .up and .down. The `GtkText` subnodes (if present) are put 150 * below the text node. The orientation of the spin button is reflected in 151 * the .vertical or .horizontal style class on the main node. 152 * 153 * # Accessiblity 154 * 155 * `GtkSpinButton` uses the %GTK_ACCESSIBLE_ROLE_SPIN_BUTTON role. 156 */ 157 public class SpinButton : Widget, CellEditableIF, EditableIF, OrientableIF 158 { 159 /** the main Gtk struct */ 160 protected GtkSpinButton* gtkSpinButton; 161 162 /** Get the main Gtk struct */ 163 public GtkSpinButton* getSpinButtonStruct(bool transferOwnership = false) 164 { 165 if (transferOwnership) 166 ownedRef = false; 167 return gtkSpinButton; 168 } 169 170 /** the main Gtk struct as a void* */ 171 protected override void* getStruct() 172 { 173 return cast(void*)gtkSpinButton; 174 } 175 176 /** 177 * Sets our main struct and passes it to the parent class. 178 */ 179 public this (GtkSpinButton* gtkSpinButton, bool ownedRef = false) 180 { 181 this.gtkSpinButton = gtkSpinButton; 182 super(cast(GtkWidget*)gtkSpinButton, ownedRef); 183 } 184 185 // add the CellEditable capabilities 186 mixin CellEditableT!(GtkSpinButton); 187 188 // add the Editable capabilities 189 mixin EditableT!(GtkSpinButton); 190 191 // add the Orientable capabilities 192 mixin OrientableT!(GtkSpinButton); 193 194 195 /** */ 196 public static GType getType() 197 { 198 return gtk_spin_button_get_type(); 199 } 200 201 /** 202 * Creates a new `GtkSpinButton`. 203 * 204 * Params: 205 * adjustment = the `GtkAdjustment` that this spin button should use 206 * climbRate = specifies by how much the rate of change in the value will 207 * accelerate if you continue to hold down an up/down button or arrow key 208 * digits = the number of decimal places to display 209 * 210 * Returns: The new `GtkSpinButton` 211 * 212 * Throws: ConstructionException GTK+ fails to create the object. 213 */ 214 public this(Adjustment adjustment, double climbRate, uint digits) 215 { 216 auto __p = gtk_spin_button_new((adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits); 217 218 if(__p is null) 219 { 220 throw new ConstructionException("null returned by new"); 221 } 222 223 this(cast(GtkSpinButton*) __p); 224 } 225 226 /** 227 * Creates a new `GtkSpinButton` with the given properties. 228 * 229 * This is a convenience constructor that allows creation 230 * of a numeric `GtkSpinButton` without manually creating 231 * an adjustment. The value is initially set to the minimum 232 * value and a page increment of 10 * @step is the default. 233 * The precision of the spin button is equivalent to the 234 * precision of @step. 235 * 236 * Note that the way in which the precision is derived works 237 * best if @step is a power of ten. If the resulting precision 238 * is not suitable for your needs, use 239 * [method@Gtk.SpinButton.set_digits] to correct it. 240 * 241 * Params: 242 * min = Minimum allowable value 243 * max = Maximum allowable value 244 * step = Increment added or subtracted by spinning the widget 245 * 246 * Returns: The new `GtkSpinButton` 247 * 248 * Throws: ConstructionException GTK+ fails to create the object. 249 */ 250 public this(double min, double max, double step) 251 { 252 auto __p = gtk_spin_button_new_with_range(min, max, step); 253 254 if(__p is null) 255 { 256 throw new ConstructionException("null returned by new_with_range"); 257 } 258 259 this(cast(GtkSpinButton*) __p); 260 } 261 262 /** 263 * Changes the properties of an existing spin button. 264 * 265 * The adjustment, climb rate, and number of decimal places 266 * are updated accordingly. 267 * 268 * Params: 269 * adjustment = a `GtkAdjustment` to replace the spin button’s 270 * existing adjustment, or %NULL to leave its current adjustment unchanged 271 * climbRate = the new climb rate 272 * digits = the number of decimal places to display in the spin button 273 */ 274 public void configure(Adjustment adjustment, double climbRate, uint digits) 275 { 276 gtk_spin_button_configure(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct(), climbRate, digits); 277 } 278 279 /** 280 * Get the adjustment associated with a `GtkSpinButton`. 281 * 282 * Returns: the `GtkAdjustment` of @spin_button 283 */ 284 public Adjustment getAdjustment() 285 { 286 auto __p = gtk_spin_button_get_adjustment(gtkSpinButton); 287 288 if(__p is null) 289 { 290 return null; 291 } 292 293 return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) __p); 294 } 295 296 /** 297 * Returns the acceleration rate for repeated changes. 298 * 299 * Returns: the acceleration rate 300 */ 301 public double getClimbRate() 302 { 303 return gtk_spin_button_get_climb_rate(gtkSpinButton); 304 } 305 306 /** 307 * Fetches the precision of @spin_button. 308 * 309 * Returns: the current precision 310 */ 311 public uint getDigits() 312 { 313 return gtk_spin_button_get_digits(gtkSpinButton); 314 } 315 316 /** 317 * Gets the current step and page the increments 318 * used by @spin_button. 319 * 320 * See [method@Gtk.SpinButton.set_increments]. 321 * 322 * Params: 323 * step = location to store step increment 324 * page = location to store page increment 325 */ 326 public void getIncrements(out double step, out double page) 327 { 328 gtk_spin_button_get_increments(gtkSpinButton, &step, &page); 329 } 330 331 /** 332 * Returns whether non-numeric text can be typed into the spin button. 333 * 334 * Returns: %TRUE if only numeric text can be entered 335 */ 336 public bool getNumeric() 337 { 338 return gtk_spin_button_get_numeric(gtkSpinButton) != 0; 339 } 340 341 /** 342 * Gets the range allowed for @spin_button. 343 * 344 * See [method@Gtk.SpinButton.set_range]. 345 * 346 * Params: 347 * min = location to store minimum allowed value 348 * max = location to store maximum allowed value 349 */ 350 public void getRange(out double min, out double max) 351 { 352 gtk_spin_button_get_range(gtkSpinButton, &min, &max); 353 } 354 355 /** 356 * Returns whether the values are corrected to the nearest step. 357 * 358 * Returns: %TRUE if values are snapped to the nearest step 359 */ 360 public bool getSnapToTicks() 361 { 362 return gtk_spin_button_get_snap_to_ticks(gtkSpinButton) != 0; 363 } 364 365 /** 366 * Gets the update behavior of a spin button. 367 * 368 * See [method@Gtk.SpinButton.set_update_policy]. 369 * 370 * Returns: the current update policy 371 */ 372 public GtkSpinButtonUpdatePolicy getUpdatePolicy() 373 { 374 return gtk_spin_button_get_update_policy(gtkSpinButton); 375 } 376 377 /** 378 * Get the value in the @spin_button. 379 * 380 * Returns: the value of @spin_button 381 */ 382 public double getValue() 383 { 384 return gtk_spin_button_get_value(gtkSpinButton); 385 } 386 387 /** 388 * Get the value @spin_button represented as an integer. 389 * 390 * Returns: the value of @spin_button 391 */ 392 public int getValueAsInt() 393 { 394 return gtk_spin_button_get_value_as_int(gtkSpinButton); 395 } 396 397 /** 398 * Returns whether the spin button’s value wraps around to the 399 * opposite limit when the upper or lower limit of the range is 400 * exceeded. 401 * 402 * Returns: %TRUE if the spin button wraps around 403 */ 404 public bool getWrap() 405 { 406 return gtk_spin_button_get_wrap(gtkSpinButton) != 0; 407 } 408 409 /** 410 * Replaces the `GtkAdjustment` associated with @spin_button. 411 * 412 * Params: 413 * adjustment = a `GtkAdjustment` to replace the existing adjustment 414 */ 415 public void setAdjustment(Adjustment adjustment) 416 { 417 gtk_spin_button_set_adjustment(gtkSpinButton, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 418 } 419 420 /** 421 * Sets the acceleration rate for repeated changes when you 422 * hold down a button or key. 423 * 424 * Params: 425 * climbRate = the rate of acceleration, must be >= 0 426 */ 427 public void setClimbRate(double climbRate) 428 { 429 gtk_spin_button_set_climb_rate(gtkSpinButton, climbRate); 430 } 431 432 /** 433 * Set the precision to be displayed by @spin_button. 434 * 435 * Up to 20 digit precision is allowed. 436 * 437 * Params: 438 * digits = the number of digits after the decimal point to be 439 * displayed for the spin button’s value 440 */ 441 public void setDigits(uint digits) 442 { 443 gtk_spin_button_set_digits(gtkSpinButton, digits); 444 } 445 446 /** 447 * Sets the step and page increments for spin_button. 448 * 449 * This affects how quickly the value changes when 450 * the spin button’s arrows are activated. 451 * 452 * Params: 453 * step = increment applied for a button 1 press. 454 * page = increment applied for a button 2 press. 455 */ 456 public void setIncrements(double step, double page) 457 { 458 gtk_spin_button_set_increments(gtkSpinButton, step, page); 459 } 460 461 /** 462 * Sets the flag that determines if non-numeric text can be typed 463 * into the spin button. 464 * 465 * Params: 466 * numeric = flag indicating if only numeric entry is allowed 467 */ 468 public void setNumeric(bool numeric) 469 { 470 gtk_spin_button_set_numeric(gtkSpinButton, numeric); 471 } 472 473 /** 474 * Sets the minimum and maximum allowable values for @spin_button. 475 * 476 * If the current value is outside this range, it will be adjusted 477 * to fit within the range, otherwise it will remain unchanged. 478 * 479 * Params: 480 * min = minimum allowable value 481 * max = maximum allowable value 482 */ 483 public void setRange(double min, double max) 484 { 485 gtk_spin_button_set_range(gtkSpinButton, min, max); 486 } 487 488 /** 489 * Sets the policy as to whether values are corrected to the 490 * nearest step increment when a spin button is activated after 491 * providing an invalid value. 492 * 493 * Params: 494 * snapToTicks = a flag indicating if invalid values should be corrected 495 */ 496 public void setSnapToTicks(bool snapToTicks) 497 { 498 gtk_spin_button_set_snap_to_ticks(gtkSpinButton, snapToTicks); 499 } 500 501 /** 502 * Sets the update behavior of a spin button. 503 * 504 * This determines whether the spin button is always 505 * updated or only when a valid value is set. 506 * 507 * Params: 508 * policy = a `GtkSpinButtonUpdatePolicy` value 509 */ 510 public void setUpdatePolicy(GtkSpinButtonUpdatePolicy policy) 511 { 512 gtk_spin_button_set_update_policy(gtkSpinButton, policy); 513 } 514 515 /** 516 * Sets the value of @spin_button. 517 * 518 * Params: 519 * value = the new value 520 */ 521 public void setValue(double value) 522 { 523 gtk_spin_button_set_value(gtkSpinButton, value); 524 } 525 526 /** 527 * Sets the flag that determines if a spin button value wraps 528 * around to the opposite limit when the upper or lower limit 529 * of the range is exceeded. 530 * 531 * Params: 532 * wrap = a flag indicating if wrapping behavior is performed 533 */ 534 public void setWrap(bool wrap) 535 { 536 gtk_spin_button_set_wrap(gtkSpinButton, wrap); 537 } 538 539 /** 540 * Increment or decrement a spin button’s value in a specified 541 * direction by a specified amount. 542 * 543 * Params: 544 * direction = a `GtkSpinType` indicating the direction to spin 545 * increment = step increment to apply in the specified direction 546 */ 547 public void spin(GtkSpinType direction, double increment) 548 { 549 gtk_spin_button_spin(gtkSpinButton, direction, increment); 550 } 551 552 /** 553 * Manually force an update of the spin button. 554 */ 555 public void update() 556 { 557 gtk_spin_button_update(gtkSpinButton); 558 } 559 560 /** 561 * Emitted when the user initiates a value change. 562 * 563 * This is a [keybinding signal](class.SignalAction.html). 564 * 565 * Applications should not connect to it, but may emit it with 566 * g_signal_emit_by_name() if they need to control the cursor 567 * programmatically. 568 * 569 * The default bindings for this signal are Up/Down and PageUp/PageDown. 570 * 571 * Params: 572 * scroll = a `GtkScrollType` to specify the speed and amount of change 573 */ 574 gulong addOnChangeValue(void delegate(GtkScrollType, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 575 { 576 return Signals.connect(this, "change-value", dlg, connectFlags ^ ConnectFlags.SWAPPED); 577 } 578 579 /** 580 * Emitted to convert the users input into a double value. 581 * 582 * The signal handler is expected to use [method@Gtk.Editable.get_text] 583 * to retrieve the text of the spinbutton and set @new_value to the 584 * new value. 585 * 586 * The default conversion uses g_strtod(). 587 * 588 * Params: 589 * newValue = return location for the new value 590 * 591 * Returns: %TRUE for a successful conversion, %FALSE if the input 592 * was not handled, and %GTK_INPUT_ERROR if the conversion failed. 593 */ 594 gulong addOnInput(int delegate(void*, SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 595 { 596 return Signals.connect(this, "input", dlg, connectFlags ^ ConnectFlags.SWAPPED); 597 } 598 599 /** 600 * Emitted to tweak the formatting of the value for display. 601 * 602 * ```c 603 * // show leading zeros 604 * static gboolean 605 * on_output (GtkSpinButton *spin, 606 * gpointer data) 607 * { 608 * GtkAdjustment *adjustment; 609 * char *text; 610 * int value; 611 * 612 * adjustment = gtk_spin_button_get_adjustment (spin); 613 * value = (int)gtk_adjustment_get_value (adjustment); 614 * text = g_strdup_printf ("%02d", value); 615 * gtk_spin_button_set_text (spin, text): 616 * g_free (text); 617 * 618 * return TRUE; 619 * } 620 * ``` 621 * 622 * Returns: %TRUE if the value has been displayed 623 */ 624 gulong addOnOutput(bool delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 625 { 626 return Signals.connect(this, "output", dlg, connectFlags ^ ConnectFlags.SWAPPED); 627 } 628 629 /** 630 * Emitted when the value is changed. 631 * 632 * Also see the [signal@Gtk.SpinButton::output] signal. 633 */ 634 gulong addOnValueChanged(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 635 { 636 return Signals.connect(this, "value-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 637 } 638 639 /** 640 * Emitted right after the spinbutton wraps from its maximum 641 * to its minimum value or vice-versa. 642 */ 643 gulong addOnWrapped(void delegate(SpinButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 644 { 645 return Signals.connect(this, "wrapped", dlg, connectFlags ^ ConnectFlags.SWAPPED); 646 } 647 }